extends GridContainer


onready var type_op = $typeOptionButton
onready var value_input = $TextEdit
onready var dialog_op = $HBoxContainer/DialogSelect


const type_values = [
	"none",
	"exists_attach_item_id",
	"exists_attach_pet_id",
	"exists_attach_pet_skill_id",
	"exists_pick_dialog_item_id",
	"exists_complete_drama_id",
	"exists_pick_change_pokemon_id",
	"exists_role_hold_badge_id",
	"exists_pick_dialog_pokemon_id",
	"exists_has_npc_fight_id",
	"exists_has_player_init_with_area_poke_id",
	"exists_has_player_sex",
]


func _ready():
	# 默认选中无
	type_op.select(type_op.get_item_index(0))
	
	

func set_data(data):
	if data["condition_type"] == "exists":
		var key = data["condition_value"]["key"]
		var index = type_values.find(key)
		type_op.select(type_op.get_item_index(index))
		value_input.text = JSON.print(data["condition_value"], "\t")
		
		dialog_op.select_value(data["dialog_id"])
	else:
		dialog_op.select_value(data["dialog_id"])
		type_op.select(type_op.get_item_index(0))
		


func get_data():
	var type_id = type_op.get_selected_id()
	var dialog_id = dialog_op.get_value()
		
	var condition_type = "none"
	
	if type_id > 0:
		condition_type = "exists"
		return {
			"condition_type": condition_type,
			"dialog_id": dialog_id,
			"condition_value": str2var(value_input.text),
		}
	else:
		return {
			"condition_type": condition_type,
			"dialog_id": dialog_id
		}
		
	


func _on_del_button_up():
	queue_free()
